package com.zj.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.zj.BaseController;
import com.zj.bean.Command;
import com.zj.bean.Custom;
import com.zj.bean.Mth;
import com.zj.bean.ReturnInfo;
import com.zj.bean.RtInfo;
import com.zj.service.ActService;

/**
 * Created by xw2sy on 2017-04-16.
 */
@Controller
@RequestMapping("/act")
public class ActController extends BaseController{

	@Autowired
	ActService actService;
    @RequestMapping(value = "custom",method=RequestMethod.GET)
    public RtInfo customGet(Custom cs){
    	System.out.println("custom");
    	List<Command> cml = actService.command(null);
    	List<Custom> csl = actService.custom(cs);
    	return new RtInfo(cml,csl);
    }
    @RequestMapping(value = "custom",method=RequestMethod.POST)
    public void custom(Custom cs){
    	System.out.println("custom: "+cs);
    	if(cs.getId()<0){
    		actService.insertCustom(cs);
    	}else{
    		actService.updateCustom(cs);
    	}
    }
    
    @RequestMapping(value = "delCustom",method=RequestMethod.GET)
    public void delCustom(int id){
    	System.out.println("delete id: "+id);
    	actService.delCustom(id);
    	redirectTo("/act/custom.html");
    }
    
    
    @RequestMapping(value = "command",method=RequestMethod.GET)
    public List<Command> commandGet(Command cmd){
    	System.out.println("command1: "+cmd);
    	List<Command> clist = actService.command(cmd);
    	return clist;
    }
    @RequestMapping(value = "command",method=RequestMethod.POST)
    public void command(Command cmd){
    	System.out.println("command2: "+cmd);
    	if(cmd.getId()<0){
    		actService.insertcommand(cmd);
    	}else{
    		actService.updateCommand(cmd);
    	}
    }
    @RequestMapping(value = "addCmd",method=RequestMethod.POST)
    public void addCmd(Mth mth){
    	System.out.println("addCmd: "+mth);
		actService.insertMth(mth);
    }
    @RequestMapping(value = "test")
    public ReturnInfo test(){
    	return new ReturnInfo(1,"成功",new Mth());
    }
}
